package com.maben.easyui.service.impl;

import com.maben.easyui.controller.vo.UserVo;
import com.maben.easyui.mapper.UserMapper;
import com.maben.easyui.pojo.User;
import com.maben.easyui.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户业务类
 */
@Service(value = "userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User queryUserById(String id) throws Exception {
        if (StringUtils.isBlank(id)){
            return null;
        }
        return userMapper.queryUserById(id);
    }

    /**
     * 通过条件查询用户列表
     */
    @Override
    public List<UserVo> queryUserListContainPage(UserVo userVo) throws Exception {
        return userMapper.queryUserListContainPage(userVo);
    }

    /**
     * 保存用户信息
     *
     */
    @Override
    public void saveUser(UserVo userVo) throws Exception {
        final Integer id = userVo.getId();
        if (id==null){
            userMapper.saveUser(userVo);
        }else {
            userMapper.updateUser(userVo);
        }
    }

    /**
     * 物理删除用户信息
     */
    @Override
    public void removeUser(UserVo userVo) throws Exception {
        final Integer id = userVo.getId();
        if (id==null){
            return;
        }
        userMapper.removeUser(id);
    }

    @Override
    public Integer queryUserCount(UserVo userVo) throws Exception {
        return userMapper.queryUserCount(userVo);
    }
}
